package com.slicktechnologies.server.compositeimplementor;

import java.util.ArrayList;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.simplesoftwares.client.library.appstructure.SuperModel;
import com.simplesoftwares.client.library.appstructure.search.MyQuerry;
import com.simplesoftwares.client.library.libservice.PersonInfoService;
import com.slicktechnologies.server.GenricServiceImpl;
import com.slicktechnologies.shared.common.businessprocesslayer.Customer;
import com.slicktechnologies.shared.common.helperlayer.PersonInfo;
import com.slicktechnologies.shared.common.personlayer.Person;

public class PersonInfoCompositeImplementor extends RemoteServiceServlet implements PersonInfoService
{
	
	
	
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 4080349707473338405L;

	@Override
	public ArrayList<PersonInfo> LoadVinfo(MyQuerry querry)
	{
	    GenricServiceImpl impl=new GenricServiceImpl();
	    ArrayList<SuperModel>arraylis=impl.getSearchResult(querry);
	    
	    ArrayList<PersonInfo> personinfoarray=new ArrayList<PersonInfo>();
	    for(SuperModel model:arraylis)
	    {
	    	PersonInfo perinfo=new PersonInfo();
	    	if(model instanceof Person)
	    	{
	    	
	    	Person per=(Person) model;
	    	
	    	//For Customers Please load company Name instead of Full Name
	    	if(model instanceof Customer)
	    	{
	    		Customer customer=(Customer) model;
	    		perinfo.setFullName(customer.getCompanyName());
	    		perinfo.setCount(per.getCount());
		    	perinfo.setCellNumber(per.getContact().get(0).getCellNo1());
		    	personinfoarray.add(perinfo);
	    	}
	    	
	    	else{
	    	perinfo.setFullName(per.getFullname());
	    	perinfo.setCount(per.getCount());
	    	perinfo.setCellNumber(per.getContact().get(0).getCellNo1());
	    	personinfoarray.add(perinfo);
	    	}
	    	}
	    	
	    	
	    }
	    
	    return personinfoarray;
		
	}

}
